package com.example.clientsideapplication;

import java.util.ArrayList;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class ViewMerchantOfferReceiver extends BroadcastReceiver {
	
	@Override
	public void onReceive(Context context, Intent intent) {
		ArrayList<Offer> offerArrayList;
		String serverAddress;
		int serverSocket;
		
		offerArrayList = (ArrayList<Offer>) intent.getSerializableExtra("offerArrayList");
		serverAddress = intent.getStringExtra("serverAddress");
		serverSocket = intent.getIntExtra("serverSocket", 21111);
		
		if(offerArrayList.size()!=0){
			Intent viewIntent = new Intent(context, ViewMerchantOfferActivity.class);
			viewIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			viewIntent.putExtra("offerArrayList", offerArrayList);
			viewIntent.putExtra("serverAddress", serverAddress);
			viewIntent.putExtra("serverSocket", serverSocket);
			context.startActivity(viewIntent);
		}
		else{
			int duration = Toast.LENGTH_LONG;
		
			Toast toast = Toast
					.makeText(
							context,
							"Non hai ancora offerte visualizzabili!",
							duration);
			toast.show();
		}
	}
}